package com.alliky.core.widget

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.animation.Animation
import android.view.animation.RotateAnimation
import android.widget.ImageView
import com.alliky.core.R

/**
 * ================================================
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2022/11/4 11:15
 * ================================================
 */
class LoadingDialog : Dialog {
    private var mLoadingDialog: LoadingDialog? = null

    constructor(context: Context, canNotCancel: Boolean) : super(context, R.style.LoadingDialog) {
        setContentView(R.layout.layout_loading_view)
        val imageView: ImageView = findViewById(R.id.iv_image)
        val animation: Animation = RotateAnimation(
            0f,
            360f,
            Animation.RELATIVE_TO_SELF,
            0.5f,
            Animation.RELATIVE_TO_SELF,
            0.5f
        )

        animation.duration = 2000
        animation.repeatCount = 100
        animation.fillAfter = true
        imageView.startAnimation(animation)

    }

    fun showDialog(context: Context, isCancel: Boolean) {
        if (context is Activity) {
            if (context.isFinishing) {
                return
            }
        }

        if (mLoadingDialog == null) {
            mLoadingDialog = LoadingDialog(context, isCancel)
        }
        mLoadingDialog?.show()
    }

    fun dismissDialog() {
        mLoadingDialog?.dismiss()
    }

}